<template>
  <div class="Login">
    <div class="login_wrap">
      <el-form ref="userForm" :rules="rules" :model="userForm">
        <el-form-item label="用户名" prop="username">
          <el-input v-model="userForm.username"></el-input>
        </el-form-item>
        <el-form-item label="密码" prop="password">
          <el-input v-model="userForm.password" type="password"></el-input>
        </el-form-item>
        <el-form-item class="button">
          <el-button type="primary" @click="onSubmit('userForm')"
            >登录</el-button
          >
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>
<script>
import { userLogin } from "@/netWork/api/Login";
export default {
  name: "Login",
  data() {
    return {
      userForm: {
        username: "admin",
        password: "123456",
      },
      rules: {
        username: [
          { required: true, message: "请输入活动名称", trigger: "blur" },
        ],
        password: [
          { required: true, message: "请输入活动名称", trigger: "blur" },
        ],
      },
    };
  },
  mounted() {},
  methods: {
    onSubmit(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          userLogin(this.userForm).then((res) => {
            if (res.data.errorno == 10000) {
              this.$message({
                type: "success", // success error warning
                message: res.data.message,
                duration: 1000,
              });
            }
          });
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
  },
  computed: {},
  watch: {},
};
</script>
<style lang="scss" scoped>
.Login {
  height: 100%;
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: #333;
  .login_wrap {
    width: 500px;
    background-color: #aaa;
    padding: 20px;
    border-radius: 20px;
    ::v-deep .el-input__inner {
      background-color: #aaa;
    }
    .button {
      text-align: right;
    }
  }
}
</style>